package com.jec;

import java.util.Properties;

import javax.xml.ws.Endpoint;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.jec.module.extern.NTNMS_ServiceImpl;

import lombok.extern.log4j.Log4j;

@Log4j
public class WebServicePublisher implements ApplicationListener<ContextRefreshedEvent> {
	
	public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
		
		try {
			
			Properties properties = Bootstrap.getApplicationProperties();
			
			String url = properties.getProperty("webservice.url", "http://127.0.0.1:8089/tcs/NTNMSWebService/NTNMS_Service?wsdl");
		
			NTNMS_ServiceImpl webservice = 
					contextRefreshedEvent.getApplicationContext().getBean(NTNMS_ServiceImpl.class);
			
			Endpoint.publish(url, webservice);
	
			log.info("Webservice started.");
		
		} catch(Exception e) {
			log.error("Start web service failed.", e);
		}

	}

}
